﻿<%@ Page Title="Chuyên gia" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="List.aspx.cs" Inherits="Dost.Khcn.Web.ChuyenGia.List" %>
<%@ Import Namespace="Resources" %>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <div class="filtering">
        Tên: <input data-bind="value: searchModel().hoTen" />
        Đơn vị: <input data-bind="value: searchModel().tenDonVi" />
        Học hàm: <select data-bind="options: hocHams, optionsText: 'Ten', optionsValue: 'Id', value: searchModel().hocHamId"></select>
        Học vị: <select data-bind="options: hocVis, optionsText: 'Ten', optionsValue: 'Id', value: searchModel().hocViId"></select>
        <button data-bind="click: search"><%=GlobalStrings.LoadRecords %></button>
        <button data-bind="click: reset">Reset</button>
    </div>
    <div id="ListContainer">
    </div>
    <p>
        <input type="button" onclick="javascript: window.location = 'New.aspx';" value="<%=GlobalStrings.AddNew %>" />
    </p>
    
    <script type="text/javascript">
        $(document).ready(function () {
            $('#ListContainer').jtable({
                title: 'Chuyên gia',
                paging: true,
                pageSize: 10,
                sorting: true,
                defaultSorting: 'Id DESC',
                actions: {
                    listAction: 'List.aspx/ChuyenGiaList',
                    deleteAction: 'List.aspx/Delete'
                },
                fields: {
                    Id: {
                        title: "STT",
                        key: true,
                        create: false,
                        edit: false,
                        width: '1%'
                    },
                    HoTen: {
                        title: '<%=GlobalStrings.FullName %>',
                        display: function(data) {
                            return '<a href="Edit.aspx?id=' + data.record.Id + '">' + data.record.HoTen + '</a>';
                        }
                    },
                    Ten: {
                        title: '<%=GlobalStrings.Name %>'
                    },
                    TenDonVi: {
                        title: 'Đơn vị'
                    },
                    DiaChiDonVi: {
                        title: 'Địa chỉ đơn vị'
                    },
                    TenHocHam: {
                        title: 'Học hàm'
                    },
                    TenHocVi: {
                        title: 'Học vị'
                    },
                    Edit: {
                        sorting: false,
                        width: '1%',
                        display: function(data) {
                            return '<input class="jtable-command-button jtable-edit-command-button" onclick="javascript:EditChuyenGia(' + data.record.Id + ');" />';
                        }
                    }
                }
            });

            ko.applyBindings(new SearchViewModel());
        });

        function EditChuyenGia(id) {
            document.location = "Edit.aspx?id=" + id;
        }
    </script>
    
    <script type="text/javascript">
        var SearchModel = {
            hoTen: ko.observable(""),
            tenDonVi: ko.observable(""),
            hocHamId: ko.observable(0),
            hocViId: ko.observable(0)
        };

        function SearchViewModel() {
            var self = this;
            
            // data
            self.searchModel = ko.observable(SearchModel);
            // hoc ham
            self.hocHams = ko.observableArray();
            $.ajax({
                url: "/DanhMuc/HocHam/List.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: true,
                success: function (data) {
                    self.hocHams(data.d);
                }
            });
            // hoc vi
            self.hocVis = ko.observableArray();
            $.ajax({
                url: "/DanhMuc/HocVi/List.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: true,
                success: function (data) {
                    self.hocVis(data.d);
                }
            });
            
            // events
            self.search = function() {
                $('#ListContainer').jtable('load', ko.toJS(self.searchModel));
            };
            
            self.reset = function () {
                self.searchModel().hoTen("");
                self.searchModel().tenDonVi("");
                self.searchModel().hocHamId(0);
                self.searchModel().hocViId(0);
                self.search();
            };

            self.search();
        }
    </script>
</asp:Content>
